package domfarr.tapestry.pages;

import org.apache.tapestry5.annotations.ApplicationState;

import domfarr.tapestry.model.User;
import domfarr.tapestry.util.Security;

public class Start {
	private String password;

	@ApplicationState
	private User user;

	private String userName;

	public String getPassword() {
		return password;
	}

	public User getUser() {
		return user;
	}

	public String getUserName() {
		return userName;
	}

	Object onSubmitFromLoginForm() {
		User authenticatedUser = Security.authenticate(getUserName(),
				getPassword());
		if (authenticatedUser != null) {
			setUser(authenticatedUser);
			return ShowAll.class;
		}

		return Register.class;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

}
